package org.jeecg.modules.demo.com.kunpeng.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.demo.com.kunpeng.entity.SupplierGrade;
import org.jeecg.modules.demo.com.kunpeng.ex.ServiceCode;
import org.jeecg.modules.demo.com.kunpeng.ex.ServiceException;
import org.jeecg.modules.demo.com.kunpeng.mapper.SupplierGradeMapper;
import org.jeecg.modules.demo.com.kunpeng.service.ISupplierGradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: 供应商等级表
 * @Author: jeecg-boot
 * @Date:   2023-01-09
 * @Version: V1.0
 */
@Service
public class SupplierGradeServiceImpl extends ServiceImpl<SupplierGradeMapper, SupplierGrade> implements ISupplierGradeService {


    @Autowired
    private SupplierGradeMapper supplierGradeMapper;

    /**
     * 新增
     * @param supplierGrade
     */
    @Override
    public void insert(SupplierGrade supplierGrade) {
        List<SupplierGrade> supplierGrades = supplierGradeMapper.queryListBySupplierGrade(supplierGrade.getSupplierGrade());
        if(supplierGrades.size()>0){
            String message="该供货商等级已存在,请重新填写！";
            throw new ServiceException(ServiceCode.ERR_CONFLICT,message);
        }
        supplierGradeMapper.insert(supplierGrade);
    }

    /**
     * 获取供货商等级列表
     * @return
     */
    @Override
    public List<String> supplierGradeList() {
        List<String> supplierGradeList = supplierGradeMapper.supplierGradeList();
        return supplierGradeList;
    }

    /**
     * 等级模糊查询
     */
    @Override
    public Page<SupplierGrade> queryListByGrade(Page<SupplierGrade> page, String keyWords) {
        Page<SupplierGrade> supplierGradePage = page.setRecords(supplierGradeMapper.queryListByGrade(page, keyWords));
        return supplierGradePage;
    }
}
